package com.example.restful.controller;

import com.example.restful.entity.Comment;
import com.example.restful.entity.Like;
import com.example.restful.entity.Status;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/statuses")
public class StatusController {
    public List<Status> getStatus(){
        List<Status> statusList=new ArrayList<>();
        Status status1=new Status();
        status1.setId(1);
        status1.setContent("编辑中");
        status1.setAuthor("user01");
        status1.setDate("2024-9-1");
        Status status2=new Status();
        status2.setId(2);
        status2.setContent("完成");
        status2.setAuthor("user02");
        status2.setDate("2024-9-2");
        Status status3=new Status();
        status3.setId(3);
        status3.setContent("已删除");
        status3.setAuthor("user03");
        status3.setDate("2024-9-3");
        statusList.add(status1);
        statusList.add(status2);
        statusList.add(status3);

        return statusList;

    }
    public List<Comment> getComments(){
        List<Comment> commentsList=new ArrayList<>();
        Comment comment1=new Comment();
        comment1.setId(1);
        comment1.setContent("编辑中");
        comment1.setAuthor("user01");
        comment1.setDate("2024-9-1");
        Comment comment2=new Comment();
        comment2.setId(2);
        comment2.setContent("完成");
        comment2.setAuthor("user01");
        comment2.setDate("2024-9-1");
        Comment comment3=new Comment();
        comment3.setId(3);
        comment3.setContent("已删除");
        comment3.setAuthor("user01");
        comment3.setDate("2024-9-1");
        commentsList.add(comment1);
        commentsList.add(comment2);
        commentsList.add(comment3);

        return commentsList;

    }
    public List<Like> getLikes(){
        List<Like> likesList=new ArrayList<>();
        Like like1=new Like();
        like1.setId(1);
        like1.setUserId(2);
        like1.setDate("2024-9-1");
        Like like2=new Like();
        like2.setId(2);
        like2.setUserId(7);
        like2.setDate("2024-9-1");
        Like like3=new Like();
        like3.setId(3);
        like3.setUserId(9);
        like3.setDate("2024-9-1");
        likesList.add(like1);
        likesList.add(like2);
        likesList.add(like3);

        return likesList;

    }
    @GetMapping("/api/statuses")
    public List<Status> getList(){
        return getStatus();
    }
    @PostMapping("/api/statuses")
    public List<Status> addStatus(@RequestBody Status entity){
        List<Status> list=getStatus();
        list.add(entity);

        return list;
    }
    @PostMapping("/api/statuses/{id}/comments")
    public List<Comment> addComment(@PathVariable Integer id,@RequestBody Comment entity){
        List<Comment> list=getComments();
        list.add(entity);
        return list;
    }

    @PostMapping("api/statuses/{id}/likes")
    public List<Like> addLike(@PathVariable Integer id,@RequestBody Like entity){
        List<Like> list=getLikes();
        list.add(entity);
        return list;
    }

















//    @RestController
//    @RequestMapping("/api")
//    public class StaController {
//        public List<Status> getStatuses(){
//            List<Status> statusList=new ArrayList<>();
//            for (int i=1;i<=12;i++){
//                String author="作者";
//                String content="文案";
//                Status status=new Status();
//                status.setAuthor(author+i);
//                status.setId(i);
//                status.setContent(content+i);
//                status.setDate("2024-9-"+i);
//                statusList.add(status);
//            }
//            return statusList;
//        }
//        public List<Comment> getComments(){
//            List<Comment> commentList=new ArrayList<>();
//            for (int i=1;i<=12;i++){
//                String author="作者";
//                String content="评论";
//                Comment comment=new Comment();
//                comment.setAuthor(author+i);
//                comment.setContent(content+i);
//                comment.setDate("2024-9-"+i);
//                commentList.add(comment);
//            }
//            return commentList;
//        }
//        public List<Like> getLikes(){
//            List<Like> likeList=new ArrayList<>();
//            for (int i=1;i<=12;i++){
//                String user="点赞用户";
//                Like like=new Like();
//                like.setUser(user+i);
//                like.setUpvote(i);
//                like.setDate("2024-9-"+i);
//                likeList.add(like);
//            }
//            return likeList;
//        }
//        @GetMapping("atuses")
//        public List<Status> getStatus(){return getStatuses();}
//        @GetMapping("/comments")
//        public List<Comment> getComment(){return getComments();}
//        @GetMapping("ke")
//        public List<Like> getLike(){return getLikes();}
//
//        @GetMapping("/{id}")
//        public Status getStatus(@PathVariable int id){return getStatuses().get(id);}
//
//        @PostMapping("/{add}")
//        public List<Status> addStatus(@RequestBody Status status){
//            List<Status> statuses=new ArrayList<>();
//            statuses.add(status);
//            return statuses;
//        }
//        @PostMapping("/update/content")
//        public List<Comment> updateComment(@PathVariable Integer content,@RequestBody Comment comment){
//            List<Comment> comments=getComments();
//            comments.get(content).setContent(comment.getContent());
//            return comments;
//        }
//        @PostMapping("/update/update")
//        public List<Like> updateLike(@PathVariable Integer upvote,@RequestBody Like like){
//            List<Like> likes=getLikes();
//            likes.get(upvote).setUpvote(like.getUpvote());
//            return likes;
//        }
//
//
//    }

}

